<?php
namespace app\home\controller;
use app\home\controller;
use app\home\model\PatrolLineM;
use myResponse\Res;
use think\Db;
use think\Request;

//设备分类控制器
class PatrolLine extends Base{
    //显示分类列表

    function getList($page = 1,$size = 10){
        $page *=1;
        $size *=1;
        $m= new PatrolLineM;
        $z=$m->listP($page,$size);
        Res::suc('ok',$z);
    }

    //添加设备分类
    function addOne(){
        //在PatrolLineModel里边通过一个指定方法实现权限添加
        $m= new PatrolLineM;
        $z=$m->addOne();
//        Db::table('patrol_device_item_task')->where('LineID',input('LineID'))->delete();
//        Db::table('patrol_device')->where('LineID',input('LineID'))->delete();
        if($z){
            Res::suc('添加成功！');
        }else {
            Res::errs('添加失败！');
        }
    }
    //修改
    function editOne(){
        //在PatrolLineModel里边通过一个指定方法实现权限添加
        $m= new PatrolLineM;
        $z=$m->editOne();
        if($z){
            Res::suc('修改成功！');
        }else {
            Res::errs('修改失败！');
        }

    }
    //删除
    function delOne(){
        $m= new PatrolLineM;
        $z=$m->delOne(input('LineID'));
        Db::table('patrol_device')->where('LineID',input('LineID'))->delete();
        Db::table('patrol_device_item_task')->where('LineID',input('LineID'))->delete();
        if($z){
            Res::suc('删除成功！');
        }else {
            Res::errs('删除失败！');
        }
    }
    //重置巡检任务
    function resetOne(){
        // 检查触发时间重置
        $time = date('Y-m-d H:i:s',time());
        $id = input('LineID');
        Db::table('patrol_device_item_task')->where('LineID',input('LineID'))->delete();
        Db::execute("update patrol_device set nearTime='{$time}' where LineID=$id");
        Res::suc('重置成功,巡检任务将按新时间生成！');
    }
    function resetLine(){
    }
}
